--[[ SLTextBarLib: Lightweight library to create text-based status bars 	]]
--[[ Author: Taffu		Rev Date: 06-Jan-11		Rev No: 1.0		 			]]

local MAJOR, MINOR = "SLTextBarLib-1.0", 1
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end

local function ColorToHex(r, g, b)
	local hex
	if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then
		print("SLTextBarLib: Value not a valid number, using default.")
	end
	if r < 1 then r = r*255 end; if g < 1 then g = g*255 end; if b < 1 then b = b*255 end
	hex = string.format("%02X%02X%02X", r, g, b)
	return hex
end

function lib:SetTextBar(str, mV, cV, wF, ecT, c1, c2, c3)
	local bar, ecC, barC, bgC = nil, "FFFFFF", "FFFFFF", "000000"
	--if c1 and type(c1) == "table" then ecC = ColorToHex(unpack(c1)) end
	--if c2 and type(c2) == "table" then barC = ColorToHex(unpack(c2)) end
	--if c3 and type(c3) == "table" then bgC = ColorToHex(unpack(c3)) end
	local barStep = 100/wF
	local barCur = (cV*(100/mV))/barStep
	local barNil = wF-barCur
	--[[ Do end cap stuff here... ]]
	local ec1, ec2 = "(", ")"
	local barCurStr, barNilStr = "", ""
	for i = 1, barCur do
		barCurStr = string.format("%s|cff%s|||r", barCurStr, barC)
	end
	for j = 1, barNil do
		barNilStr = string.format("%s|cff%s|||r", barNilStr, bgC)
	end
	str:SetFormattedText("|cff%s%s|r%s%s|cff%s%s|r", ecC, ec1, barCurStr, barNilStr, ecC, ec2)
end